Imports System.Data
Imports System.Data.SqlClient

Public Class CheckMemberPackage

    Dim MemberID As Integer

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim frm As New People
        frm.SearchMode = True
        frm.ShowDialog()

        Me.txtMemberNo.Text = FGT_MemberNo
        FGT_MemberNo = ""

        SearchMemberInfo(Me.txtMemberNo.Text)
    End Sub


    Private Sub SearchMemberInfo(ByVal MemberCode As String)
        Dim str As String
        str = "SELECT * FROM People WHERE CodeNo = @Code"
        Dim cmd As New SqlCommand(str, gCnnPCE)
        cmd.Parameters.AddWithValue("@Code", MemberCode)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            Me.lblMemberName.Text = dr.Item("Name").ToString
            MemberID = dr.Item("ID")
        End While
        dr.Close()


        RefreshList()


        'If Me.ImageListBoxControl1.ItemCount <> 0 Then
        '    'MsgBox(Me.ImageListBoxControl1.Items(0).ToString, MsgBoxStyle.Information)
        '    ShowPackageDetail(Me.ImageListBoxControl1.Items.Item(1).Value)
        'End If



    End Sub

    Private Sub RefreshList()
        Dim str As String
        Dim cmd As New SqlCommand("", gCnnPCE)

        str = "SELECT * FROM MemberPackageView WHERE MemberID = " & MemberID
        cmd.CommandText = str
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds, "MemberPackage")
        Me.ImageListBoxControl1.DataSource = ds.Tables(0)
        Me.ImageListBoxControl1.ValueMember = "PackageID"
        Me.ImageListBoxControl1.DisplayMember = "PackageName"
        Me.ImageListBoxControl1.ImageIndexMember = 1

    End Sub

    Private Sub txtMemberNo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMemberNo.KeyDown
        If e.KeyCode = Keys.Enter Then
            If Me.txtMemberNo.Text <> "" Then
                SearchMemberInfo(Me.txtMemberNo.Text.Trim)
            End If
        End If
    End Sub

    Private Sub ImageListBoxControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ImageListBoxControl1.Click
        If Me.ImageListBoxControl1.ItemCount = 0 Then
            Exit Sub
        End If

  
        ShowPackageDetail(Me.ImageListBoxControl1.SelectedValue)


    End Sub

    Private Sub ShowPackageDetail(ByVal ID As Integer)

        'Me.chkItem01.Checked = False
        'Me.chkItem02.Checked = False
        'Me.chkItem03.Checked = False
        'Me.chkItem04.Checked = False
        'Me.chkItem05.Checked = False
        'Me.chkItem06.Checked = False
        'Me.chkItem07.Checked = False
        'Me.chkItem08.Checked = False
        'Me.chkItem09.Checked = False
        'Me.chkItem10.Checked = False
        'Me.chkItem11.Checked = False
        'Me.chkItem12.Checked = False
        'Me.chkItem13.Checked = False
        'Me.chkItem14.Checked = False
        'Me.chkItem15.Checked = False
        'Me.chkItem16.Checked = False
        'Me.chkItem17.Checked = False
        'Me.chkItem18.Checked = False
        'Me.chkItem19.Checked = False
        'Me.chkItem20.Checked = False


        Dim str As String
        str = "SELECT * FROM Packages WHERE ID = " & ID
        Dim cmd As New SqlCommand(str, gCnnPCE)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader
        While dr.Read
            Me.lblPackageName.Text = dr.Item("PackageName").ToString
            Me.chkItem01.Text = dr.Item("Item01").ToString
            If dr.Item("Item01").ToString <> "" Then
                chkItem01.Text = dr.Item("Item01").ToString
                Me.chkItem01.Visible = True
            Else
                Me.chkItem01.Visible = False
            End If

            Me.chkItem02.Text = dr.Item("Item02").ToString
            If dr.Item("Item02").ToString <> "" Then
                chkItem02.Text = dr.Item("Item02").ToString
                Me.chkItem02.Visible = True
            Else
                Me.chkItem02.Visible = False
            End If

            Me.chkItem03.Text = dr.Item("Item03").ToString
            If dr.Item("Item03").ToString <> "" Then
                chkItem03.Text = dr.Item("Item03").ToString
                Me.chkItem03.Visible = True
            Else
                Me.chkItem03.Visible = False
            End If

            Me.chkItem04.Text = dr.Item("Item04").ToString
            If dr.Item("Item04").ToString <> "" Then
                chkItem04.Text = dr.Item("Item04").ToString
                Me.chkItem04.Visible = True
            Else
                Me.chkItem04.Visible = False
            End If

            Me.chkItem05.Text = dr.Item("Item05").ToString
            If dr.Item("Item05").ToString <> "" Then
                chkItem05.Text = dr.Item("Item05").ToString
                Me.chkItem05.Visible = True
            Else
                Me.chkItem05.Visible = False
            End If

            Me.chkItem06.Text = dr.Item("Item06").ToString
            If dr.Item("Item06").ToString <> "" Then
                chkItem06.Text = dr.Item("Item06").ToString
                Me.chkItem06.Visible = True
            Else
                Me.chkItem06.Visible = False
            End If

            Me.chkItem07.Text = dr.Item("Item07").ToString
            If dr.Item("Item07").ToString <> "" Then
                chkItem07.Text = dr.Item("Item07").ToString
                Me.chkItem07.Visible = True
            Else
                Me.chkItem07.Visible = False
            End If

            Me.chkItem08.Text = dr.Item("Item08").ToString
            If dr.Item("Item08").ToString <> "" Then
                chkItem08.Text = dr.Item("Item08").ToString
                Me.chkItem08.Visible = True
            Else
                Me.chkItem08.Visible = False
            End If

            Me.chkItem09.Text = dr.Item("Item09").ToString
            If dr.Item("Item09").ToString <> "" Then
                chkItem09.Text = dr.Item("Item09").ToString
                Me.chkItem09.Visible = True
            Else
                Me.chkItem09.Visible = False
            End If

            Me.chkItem10.Text = dr.Item("Item10").ToString
            If dr.Item("Item10").ToString <> "" Then
                chkItem10.Text = dr.Item("Item10").ToString
                Me.chkItem10.Visible = True
            Else
                Me.chkItem10.Visible = False
            End If

            Me.chkItem11.Text = dr.Item("Item11").ToString
            If dr.Item("Item11").ToString <> "" Then
                chkItem11.Text = dr.Item("Item11").ToString
                Me.chkItem11.Visible = True
            Else
                Me.chkItem11.Visible = False
            End If

            Me.chkItem12.Text = dr.Item("Item12").ToString
            If dr.Item("Item12").ToString <> "" Then
                chkItem12.Text = dr.Item("Item12").ToString
                Me.chkItem12.Visible = True
            Else
                Me.chkItem12.Visible = False
            End If

            Me.chkItem13.Text = dr.Item("Item13").ToString
            If dr.Item("Item13").ToString <> "" Then
                chkItem13.Text = dr.Item("Item13").ToString
                Me.chkItem13.Visible = True
            Else
                Me.chkItem13.Visible = False
            End If

            Me.chkItem14.Text = dr.Item("Item14").ToString
            If dr.Item("Item14").ToString <> "" Then
                chkItem14.Text = dr.Item("Item14").ToString
                Me.chkItem14.Visible = True
            Else
                Me.chkItem14.Visible = False
            End If

            Me.chkItem15.Text = dr.Item("Item15").ToString
            If dr.Item("Item15").ToString <> "" Then
                chkItem15.Text = dr.Item("Item15").ToString
                Me.chkItem15.Visible = True
            Else
                Me.chkItem15.Visible = False
            End If

            Me.chkItem16.Text = dr.Item("Item16").ToString
            If dr.Item("Item16").ToString <> "" Then
                chkItem16.Text = dr.Item("Item16").ToString
                Me.chkItem16.Visible = True
            Else
                Me.chkItem16.Visible = False
            End If

            Me.chkItem17.Text = dr.Item("Item17").ToString
            If dr.Item("Item17").ToString <> "" Then
                chkItem17.Text = dr.Item("Item17").ToString
                Me.chkItem17.Visible = True
            Else
                Me.chkItem17.Visible = False
            End If

            Me.chkItem18.Text = dr.Item("Item18").ToString
            If dr.Item("Item18").ToString <> "" Then
                chkItem18.Text = dr.Item("Item18").ToString
                Me.chkItem18.Visible = True
            Else
                Me.chkItem18.Visible = False
            End If

            Me.chkItem19.Text = dr.Item("Item19").ToString
            If dr.Item("Item19").ToString <> "" Then
                chkItem19.Text = dr.Item("Item19").ToString
                Me.chkItem19.Visible = True
            Else
                Me.chkItem19.Visible = False
            End If

            Me.chkItem20.Text = dr.Item("Item20").ToString
            If dr.Item("Item20").ToString <> "" Then
                chkItem20.Text = dr.Item("Item20").ToString
                Me.chkItem20.Visible = True
            Else
                Me.chkItem20.Visible = False
            End If


        End While
        dr.Close()




        If MemberID <> 0 Then
            str = "SELECT * FROM MemberPackageView WHERE MemberID = @MemberID AND PackageID = @PackageID"
            cmd.CommandText = str
            cmd.Parameters.Clear()
            cmd.Parameters.AddWithValue("@MemberID", MemberID)
            cmd.Parameters.AddWithValue("@PackageID", Me.ImageListBoxControl1.SelectedValue)
            dr = cmd.ExecuteReader
            While dr.Read
                Me.chkItem01.EditValue = dr.Item("Item01YesNo")
                Me.chkItem02.EditValue = dr.Item("Item02YesNo")
                Me.chkItem03.EditValue = dr.Item("Item03YesNo")
                Me.chkItem04.EditValue = dr.Item("Item04YesNo")
                Me.chkItem05.EditValue = dr.Item("Item05YesNo")
                Me.chkItem06.EditValue = dr.Item("Item06YesNo")
                Me.chkItem07.EditValue = dr.Item("Item07YesNo")
                Me.chkItem08.EditValue = dr.Item("Item08YesNo")
                Me.chkItem09.EditValue = dr.Item("Item09YesNo")
                Me.chkItem10.EditValue = dr.Item("Item10YesNo")
                Me.chkItem11.EditValue = dr.Item("Item11YesNo")
                Me.chkItem12.EditValue = dr.Item("Item12YesNo")
                Me.chkItem13.EditValue = dr.Item("Item13YesNo")
                Me.chkItem14.EditValue = dr.Item("Item14YesNo")
                Me.chkItem15.EditValue = dr.Item("Item15YesNo")
                Me.chkItem16.EditValue = dr.Item("Item16YesNo")
                Me.chkItem17.EditValue = dr.Item("Item17YesNo")
                Me.chkItem18.EditValue = dr.Item("Item18YesNo")
                Me.chkItem19.EditValue = dr.Item("Item19YesNo")
                Me.chkItem20.EditValue = dr.Item("Item20YesNo")
            End While
            dr.Close()

        End If



    End Sub

    Private Sub CheckMemberPackage_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadIcon(Me)
        Dim str As String
        Dim cmd As New SqlCommand(str, gCnnPCE)
        str = "SELECT * FROM MemberPackageView WHERE MemberID = " & 0
        cmd.CommandText = str
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet
        da.Fill(ds, "MemberPackage")
        Me.ImageListBoxControl1.DataSource = ds.Tables(0)
        Me.ImageListBoxControl1.ValueMember = "PackageID"
        Me.ImageListBoxControl1.DisplayMember = "PackageName"
        Me.ImageListBoxControl1.ImageIndexMember = 1

    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        '***************************************[ DIM Param ]**************************************

        Dim _MemberID As Integer
        Dim _PackageID As Integer
        Dim _SignedDate As DateTime
        Dim _Item01YesNo As Integer
        Dim _Item02YesNo As Integer
        Dim _Item03YesNo As Integer
        Dim _Item04YesNo As Integer
        Dim _Item05YesNo As Integer
        Dim _Item06YesNo As Integer
        Dim _Item07YesNo As Integer
        Dim _Item08YesNo As Integer
        Dim _Item09YesNo As Integer
        Dim _Item10YesNo As Integer
        Dim _Item11YesNo As Integer
        Dim _Item12YesNo As Integer
        Dim _Item13YesNo As Integer
        Dim _Item14YesNo As Integer
        Dim _Item15YesNo As Integer
        Dim _Item16YesNo As Integer
        Dim _Item17YesNo As Integer
        Dim _Item18YesNo As Integer
        Dim _Item19YesNo As Integer
        Dim _Item20YesNo As Integer


        '***************************************[ Param = ]**************************************

        _MemberID = MemberID
        _PackageID = Me.ImageListBoxControl1.SelectedValue
        _Item01YesNo = Me.chkItem01.EditValue
        _Item02YesNo = Me.chkItem02.EditValue
        _Item03YesNo = Me.chkItem03.EditValue
        _Item04YesNo = Me.chkItem04.EditValue
        _Item05YesNo = Me.chkItem05.EditValue
        _Item06YesNo = Me.chkItem06.EditValue
        _Item07YesNo = Me.chkItem07.EditValue
        _Item08YesNo = Me.chkItem08.EditValue
        _Item09YesNo = Me.chkItem09.EditValue
        _Item10YesNo = Me.chkItem10.EditValue
        _Item11YesNo = Me.chkItem11.EditValue
        _Item12YesNo = Me.chkItem12.EditValue
        _Item13YesNo = Me.chkItem13.EditValue
        _Item14YesNo = Me.chkItem14.EditValue
        _Item15YesNo = Me.chkItem15.EditValue
        _Item16YesNo = Me.chkItem16.EditValue
        _Item17YesNo = Me.chkItem17.EditValue
        _Item18YesNo = Me.chkItem18.EditValue
        _Item19YesNo = Me.chkItem19.EditValue
        _Item20YesNo = Me.chkItem20.EditValue

        UPDATE2MemberPackage(_MemberID, _PackageID, _Item01YesNo, _Item02YesNo, _Item03YesNo, _Item04YesNo, _Item05YesNo, _Item06YesNo, _Item07YesNo, _Item08YesNo, _
                                                 _Item09YesNo, _Item10YesNo, _Item11YesNo, _Item12YesNo, _Item13YesNo, _Item14YesNo, _Item15YesNo, _Item16YesNo, _Item17YesNo, _
                                                 _Item18YesNo, _Item19YesNo, _Item20YesNo)

    End Sub


    Private Sub UPDATE2MemberPackage( _
 ByVal MemberID As Integer, ByVal PackageID As Integer, ByVal Item01YesNo As Integer, _
ByVal Item02YesNo As Integer, ByVal Item03YesNo As Integer, ByVal Item04YesNo As Integer, ByVal Item05YesNo As Integer, ByVal Item06YesNo As Integer, _
ByVal Item07YesNo As Integer, ByVal Item08YesNo As Integer, ByVal Item09YesNo As Integer, ByVal Item10YesNo As Integer, ByVal Item11YesNo As Integer, _
ByVal Item12YesNo As Integer, ByVal Item13YesNo As Integer, ByVal Item14YesNo As Integer, ByVal Item15YesNo As Integer, ByVal Item16YesNo As Integer, _
ByVal Item17YesNo As Integer, ByVal Item18YesNo As Integer, ByVal Item19YesNo As Integer, ByVal Item20YesNo As Integer)
        Dim str As String
        Dim cmd As New SqlCommand(str, gCnnPCE)
        str = "UPDATE MemberPackage SET " & _
      "Item01YesNo= @Item01YesNo," & _
      "Item02YesNo= @Item02YesNo, Item03YesNo= @Item03YesNo, Item04YesNo= @Item04YesNo, Item05YesNo= @Item05YesNo, Item06YesNo= @Item06YesNo," & _
      "Item07YesNo= @Item07YesNo, Item08YesNo= @Item08YesNo, Item09YesNo= @Item09YesNo, Item10YesNo= @Item10YesNo, Item11YesNo= @Item11YesNo," & _
      "Item12YesNo= @Item12YesNo, Item13YesNo= @Item13YesNo, Item14YesNo= @Item14YesNo, Item15YesNo= @Item15YesNo, Item16YesNo= @Item16YesNo," & _
      "Item17YesNo= @Item17YesNo, Item18YesNo= @Item18YesNo, Item19YesNo= @Item19YesNo, Item20YesNo= @Item20YesNo " & _
      "WHERE MemberID = @MemberID AND PackageID= @PackageID"

        cmd.CommandText = str
        cmd.Parameters.AddWithValue("@MemberID", MemberID)
        cmd.Parameters.AddWithValue("@PackageID", PackageID)
        cmd.Parameters.AddWithValue("@Item01YesNo", Item01YesNo)
        cmd.Parameters.AddWithValue("@Item02YesNo", Item02YesNo)
        cmd.Parameters.AddWithValue("@Item03YesNo", Item03YesNo)
        cmd.Parameters.AddWithValue("@Item04YesNo", Item04YesNo)
        cmd.Parameters.AddWithValue("@Item05YesNo", Item05YesNo)
        cmd.Parameters.AddWithValue("@Item06YesNo", Item06YesNo)
        cmd.Parameters.AddWithValue("@Item07YesNo", Item07YesNo)
        cmd.Parameters.AddWithValue("@Item08YesNo", Item08YesNo)
        cmd.Parameters.AddWithValue("@Item09YesNo", Item09YesNo)
        cmd.Parameters.AddWithValue("@Item10YesNo", Item10YesNo)
        cmd.Parameters.AddWithValue("@Item11YesNo", Item11YesNo)
        cmd.Parameters.AddWithValue("@Item12YesNo", Item12YesNo)
        cmd.Parameters.AddWithValue("@Item13YesNo", Item13YesNo)
        cmd.Parameters.AddWithValue("@Item14YesNo", Item14YesNo)
        cmd.Parameters.AddWithValue("@Item15YesNo", Item15YesNo)
        cmd.Parameters.AddWithValue("@Item16YesNo", Item16YesNo)
        cmd.Parameters.AddWithValue("@Item17YesNo", Item17YesNo)
        cmd.Parameters.AddWithValue("@Item18YesNo", Item18YesNo)
        cmd.Parameters.AddWithValue("@Item19YesNo", Item19YesNo)
        cmd.Parameters.AddWithValue("@Item20YesNo", Item20YesNo)

        If cmd.ExecuteNonQuery() > 0 Then
            MsgBox("Save Successfully", MsgBoxStyle.Information)
            Me.Close()
        Else
            MsgBox("Fail to Save", MsgBoxStyle.Information)
        End If


    End Sub

  
    Private Sub btnDismiss_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDismiss.Click
        If Me.ImageListBoxControl1.ItemCount = 0 Then
            Exit Sub
        End If

        If MsgBox("Are You Sure Want to Dismiss This Package ?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            Exit Sub
        End If

        Dim str As String
        str = "DELETE FROM MemberPackage WHERE MemberID = " & MemberID & " AND PackageID = " & Me.ImageListBoxControl1.SelectedValue
        Dim cmd As New SqlCommand(str, gCnnPCE)
        If cmd.ExecuteNonQuery > 0 Then
            MsgBox("Dismiss Successfully", MsgBoxStyle.Information)
            RefreshList()
        Else
            MsgBox("Fail to Dismiss", MsgBoxStyle.Exclamation)
        End If

    End Sub
End Class